package app.controller.core
{
	import app.model.flare.proxies.FlareDataProxy;
	
	import com.adobe.serialization.json.JSON;
	
	import flash.events.Event;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	
	import org.puremvc.as3.multicore.interfaces.INotification;
	import org.puremvc.as3.multicore.patterns.command.SimpleCommand;

	public class OpenJSONCmd extends SimpleCommand
	{
		override public function execute(notification:INotification):void{
			var url:String = notification.getType();
			aquire( url )
		}
		
		private function aquire( url:String ):void{
			var loader:URLLoader = new URLLoader();
			loader.addEventListener(Event.COMPLETE, onLoadComplete);
			loader.load(new URLRequest(url));
		}
		
		private function onLoadComplete(event:Event):void{
			var a:Array,
				loader:URLLoader;
			loader = URLLoader( event.target );
			a = JSON.decode(loader.data as String) as Array;
			parse( a );
		}
		
		private function parse( a:Array ):void{
			FlareDataProxy(facade.retrieveProxy(FlareDataProxy.NAME)).parse( a );
		}
		
	}
}